package myky.com.doctorapp.ui

import android.graphics.Color
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.OrientationHelper
import android.view.View
import com.gyf.barlibrary.ImmersionBar
import kotlinx.android.synthetic.main.activity_my_consult.*
import kotlinx.android.synthetic.main.public_common_title.*
import myky.com.doctorapp.R
import myky.com.doctorapp.adapter.MyConsultAdapter
import myky.com.doctorapp.base.BaseActivity
import myky.com.doctorapp.contract.MyConsultContract
import myky.com.doctorapp.entity.MyConsultEntity
import myky.com.doctorapp.entity.PageEntity
import myky.com.doctorapp.presenter.MyConsultPresenter
import myky.com.doctorapp.utils.Constants
import myky.com.doctorapp.wight.RecycleViewDivider

/**
 * Description: 我的咨询
 * @author xiangyao
 * Created by 2019/3/6 3:43 PM
 */
class MyConsultRecordActivity : BaseActivity<MyConsultPresenter, MutableList<MyConsultEntity.SpecialistConsultsEntity>>(), MyConsultContract.View {

    lateinit var myConsultAdapter: MyConsultAdapter

    lateinit var datas: MutableList<MyConsultEntity.SpecialistConsultsEntity>

    lateinit var pageEntity: PageEntity

    override fun reloadActivity() {
    }

    override fun injectTarget(): View = findViewById(R.id.activity_new_consult_list_smartRefresh)

    override fun initData() {
        mPresenter.findMyConsult(0, 10)
    }

    override fun initView() {

        datas = ArrayList()


        conmonTitleTextView.text = "我的咨询"


        ImmersionBar.with(this)
                .statusBarColor(R.color.colorPrimary)
                .titleBar(R.id.conmonLayout)
                .init()



        myConsultAdapter = MyConsultAdapter(datas)

        activity_new_consult_list_recycler.layoutManager = LinearLayoutManager(this)

        activity_new_consult_list_recycler.addItemDecoration(RecycleViewDivider(this, OrientationHelper.VERTICAL, 20, Color.BLUE))

        activity_new_consult_list_recycler.adapter = myConsultAdapter


        backLayout.setOnClickListener {

            finish()
        }

        myConsultAdapter.setOnItemChildClickListener { adapter, _, position ->

            val specialistConsultsEntity = (adapter as MyConsultAdapter).data[position]

            val id = specialistConsultsEntity.id

            var bundle = Bundle()

            bundle.putInt(Constants.CONSULTID, id)

            startActivity(ConsultDetailsActivity::class.java, bundle)


        }


    }

    override fun getContenView(): Int = R.layout.activity_my_consult

    override fun showDataSuccess(mDatas: MutableList<MyConsultEntity.SpecialistConsultsEntity>) {

        datas.addAll(mDatas)


        myConsultAdapter.notifyDataSetChanged()


    }

    override fun showPageEntity(pageEntity: PageEntity?) {
    }

    override fun getPresenter(): MyConsultPresenter {
        return MyConsultPresenter()
    }
}